#[macro_use]
extern crate log;

#[macro_use]
extern crate serde_derive;

extern crate tungstenite as ws;
extern crate serde;
#[macro_use]
extern crate serde_json as json;

extern crate mio;

#[macro_use]
extern crate mysql;

#[macro_use]
extern crate rustful;

#[macro_use]
extern crate lazy_static;

extern crate uuid;

mod conf;
mod game;
//mod http;

use std::mem;

//extern crate tungstenite;
//use std::net::TcpListener;
//use std::thread::spawn;
//use tungstenite::server::accept;
//
//fn main(){
//    /// A WebSocket echo server
//    let server = TcpListener::bind("127.0.0.1:8020").unwrap();
//    for stream in server.incoming() {
//        spawn (move || {
//            let mut websocket = accept(stream.unwrap()).unwrap();
//            loop {
//                let msg = websocket.read_message().unwrap();
//
//                if msg.is_binary() || msg.is_text() {
//                    websocket.write_message(msg).unwrap();
//                }
//            }
//        });
//    }
//}





fn main() {
    //初始化日志配置
    conf::logger::logger_init();

    info!("MyProgram v0.0.1 starting up!");
    debug!("DEBUG output enabled.");
    trace!("TRACE output enabled.");
//    info!(target: "overly-verbose-target", "hey, another library here, we're starting.");


//    http::run();
    //启动游戏循环
    game::run();
//    let mut board = Board::new();
//    board.swap();
//    println!("{:?}", board);
    info!("Chess server shutting down!")
}

#[derive(Debug)]
struct Point(u8);

#[derive(Debug)]
struct Board{
    x: Point,
    y: Point
}

impl Board{
    pub fn new() -> Board{
        Board{
            x: Point(2),
            y: Point(3)
        }
    }

    pub fn swap(&mut self){
        mem::swap(&mut self.x, &mut self.y);
    }
}